package com.kr.weitao.util.mongodb;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;

@Configuration
@EnableConfigurationProperties(MongodbProperties.class)
@Log4j2
public class MongodbAutoConfiguration {

  @Autowired private MongodbProperties mongodbProperties;

  @Bean
  public MongodbClient mongodbConnection() {
    log.info("初始化---Mongodb---");
    MongodbClient mongodbClient = new MongodbClient();
    mongodbClient.setMongodbProperties(mongodbProperties);
    return mongodbClient;
  }

  @Bean(name = "mongoTemplate")
  public MongoTemplate getMongoTemplate() {
    log.info("初始化---Mongodb---");
    MongodbClient mongodbClient = new MongodbClient();
    mongodbClient.setMongodbProperties(mongodbProperties);
    return mongodbClient.getMongoTemplate();
  }
}
